package io.renren.modules.sys.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.modules.sys.dao.DepotheadDao;
import io.renren.modules.sys.entity.DepotheadEntity;
import io.renren.modules.sys.service.DepotheadService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Service("depotheadService")
public class DepotheadServiceImpl extends ServiceImpl<DepotheadDao, DepotheadEntity> implements DepotheadService {

    protected static Logger logger = LoggerFactory.getLogger(DepotheadServiceImpl.class);

    @Autowired
    DepotheadDao depotheadDao;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        Page<DepotheadEntity> page = this.selectPage(
                new Query<DepotheadEntity>(params).getPage(),
                new EntityWrapper<DepotheadEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public List getHeaderIdByMaterial(Map<String, Object> params){
       return depotheadDao.getHeaderIdByMaterial(params);
    }

    @Override
    public String findMaterialsListByHeaderId(Map<String, Object> params){
        return depotheadDao.findMaterialsListByHeaderId( params);
    }

    @Override
    public List<DepotheadEntity> findBy(Map<String, Object> params){
        return depotheadDao.findBy(params);
    }
	
	@Override
    public List findStatementAccount(Map<String, Object> params) {
        params.put("pageNo", Integer.parseInt(params.get("pageNo")+"")-1);
        params.put("pageSize", Integer.parseInt(params.get("pageSize")+""));
        List dataList = depotheadDao.findStatementAccount(params);
        return dataList;
	}

    @Override
    public List findInOutMaterialCount(Map<String, Object> params) {
        params.put("pageNo", Integer.parseInt(params.get("pageNo")+"")-1);
        params.put("pageSize", Integer.parseInt(params.get("pageSize")+""));
        if (params.get("ProjectId") != null && !"".equals(params.get("ProjectId").toString())) {
            params.put("DepotIds", "");
        }
        if (params.get("DepotIds") != null) {
            String dids = (String)params.get("DepotIds");
            String[] arr = dids.split(",");
            List list = new ArrayList();
            for (String s : arr) {
                list.add(s);
            }
            params.put("DepotIds", list);
        }
        logger.info(">>>>>>>>>>>>>>>>>>> params: " + params);
        List dataList = depotheadDao.findInOutMaterialCount(params);
        return dataList;
    }

    /**
     *
     * @param params
     * @return
     */
    @Override
    public List findInDetail(Map<String, Object> params) {
        params.put("pageNo", Integer.parseInt(params.get("pageNo")+"")-1);
        params.put("pageSize", Integer.parseInt(params.get("pageSize")+""));
        if (params.get("ProjectId") != null && !"".equals(params.get("ProjectId").toString())) {
            params.put("DepotIds", "");
        }
        if (params.get("DepotIds") != null) {
            String dids = (String)params.get("DepotIds");
            String[] arr = dids.split(",");
            List list = new ArrayList();
            for (String s : arr) {
                list.add(s);
            }
            params.put("DepotIds", list);
        }
        logger.info(">>>>>>>>>>>>>>>>>>> params: " + params);
        List dataList = depotheadDao.findInDetail(params);
        return dataList;
    }

    @Override
    public Double findAllMoney(String getS, String type, String subType, String mode) {
        HashMap<String, Object> map = new HashMap<>();
        map.put("organId",getS);
        map.put("type",type);
        map.put("subType",subType);
        map.put("mode",mode);
        return depotheadDao.findAllMoney(map);
    }
}
